﻿using System;
using UniRx;
using UniRx.Triggers;
using UnityEngine;

namespace Studio
{
	// Token: 0x020005DA RID: 1498
	public class GripMove : MonoBehaviour
	{
		// Token: 0x170004B9 RID: 1209
		// (get) Token: 0x06002650 RID: 9808 RVA: 0x000E0A34 File Offset: 0x000DEC34
		private Transform transCamera
		{
			get
			{
				if (this.m_TransCamera == null)
				{
					this.m_TransCamera = this.objCameraRig.transform;
				}
				return this.m_TransCamera;
			}
		}

		// Token: 0x06002651 RID: 9809 RVA: 0x000E0A60 File Offset: 0x000DEC60
		private void StartMove()
		{
			this.transTrack = this.trackedObject.transform;
			this.posOld = this.transTrack.localPosition;
			this.basePos = this.transCamera.position;
		}

		// Token: 0x06002652 RID: 9810 RVA: 0x000E0A98 File Offset: 0x000DEC98
		private void Move()
		{
			if (this.transTrack == null)
			{
				return;
			}
			Vector3 direction = this.posOld - this.transTrack.localPosition;
			this.transCamera.position = this.basePos + this.transCamera.TransformDirection(direction);
		}

		// Token: 0x06002653 RID: 9811 RVA: 0x000E0AF0 File Offset: 0x000DECF0
		private void EndMove()
		{
			this.transTrack = null;
		}

		// Token: 0x06002654 RID: 9812 RVA: 0x000E0AFC File Offset: 0x000DECFC
		private void Start()
		{
			SteamVR_Controller.Device device = SteamVR_Controller.Input((int)this.trackedObject.index);
			(from _ in this.UpdateAsObservable()
			where this.enabled
			where device.GetPressDown(4UL)
			select _).Subscribe(delegate(Unit _)
			{
				this.StartMove();
			});
			(from _ in this.UpdateAsObservable()
			where this.enabled
			where device.GetPress(4UL)
			select _).Subscribe(delegate(Unit _)
			{
				this.Move();
			});
			(from _ in this.UpdateAsObservable()
			where this.enabled
			where device.GetPressUp(4UL)
			select _).Subscribe(delegate(Unit _)
			{
				this.EndMove();
			});
		}

		// Token: 0x06002655 RID: 9813 RVA: 0x000E0BDC File Offset: 0x000DEDDC
		private void OnDisable()
		{
			this.EndMove();
		}

		// Token: 0x04002669 RID: 9833
		[SerializeField]
		private GameObject objCameraRig;

		// Token: 0x0400266A RID: 9834
		private Transform m_TransCamera;

		// Token: 0x0400266B RID: 9835
		[SerializeField]
		private SteamVR_TrackedObject trackedObject;

		// Token: 0x0400266C RID: 9836
		private Vector3 posOld = Vector3.zero;

		// Token: 0x0400266D RID: 9837
		private Transform transTrack;

		// Token: 0x0400266E RID: 9838
		private Vector3 basePos = Vector3.zero;
	}
}
